package org.csu.mypetstoret.controller;

import org.csu.mypetstoret.domain.Item;
import org.csu.mypetstoret.domain.Product;
import org.csu.mypetstoret.service.CatelogService;
import org.csu.mypetstoret.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.annotation.Resource;
import java.util.List;

@Controller("ViewProductController")
@RequestMapping("/product")
@SessionAttributes(value = {"itemlist"})
public class ViewProductController {
    @Resource(name = "CatelogService")
    private CatelogService catelogService;
    @Autowired
    private ProductService productService;

    @GetMapping("/viewProduct")
    public String viewProduct(@RequestParam("productId") String productId, @RequestParam("categoryId") String categoryId, Model model)
    {
    System.out.println(productId);
    System.out.println(categoryId);
    Product product=productService.getProduct(productId);
    List<Product> productList=productService.getProductListByCategory(categoryId);
    List <Item>itemList=catelogService.getItemListByProduct(productId);
    model.addAttribute("productId",productId);
    model.addAttribute("product",product);
    model.addAttribute("productList",productList);
    model.addAttribute("itemList",itemList);
//        model.addAttribute()
        return "/catalog/Product";
    }

}
